package com.rui.service.impl;

import com.rui.domain.InternshipLogger;
import com.rui.domain.InternshipLoggerExample;
import com.rui.mapper.InternshipLoggerMapper;
import com.rui.mapper.MyCustomMapper;
import com.rui.service.InternshipLoggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("internshipLoggerService")
public class InternshipLoggerServiceImpl implements InternshipLoggerService {

    @Autowired
    private InternshipLoggerMapper internshipLoggerMapper;
    @Autowired
    private MyCustomMapper myCustomMapper;

    @Override
    public boolean addInternshipLogger(InternshipLogger internshipLogger) {
        int row = internshipLoggerMapper.insert(internshipLogger);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<InternshipLogger> findInternshipLogByStudentNumber(String studentNumber) {
        List<InternshipLogger> internshipLoggers = myCustomMapper.findInternshipLogByStuNo(studentNumber);
//        InternshipLoggerExample example = new InternshipLoggerExample();
//        InternshipLoggerExample.Criteria criteria = example.createCriteria();
//        criteria.andStudentNumberEqualTo(studentNumber);
//        List<InternshipLogger> internshipLoggers = internshipLoggerMapper.selectByExample(example);
        if (internshipLoggers != null && internshipLoggers.size() > 0) {
            return internshipLoggers;
        }
        return null;
    }

    @Override
    public boolean updateInternshipLogger(InternshipLogger internshipLogger) {
        int row = internshipLoggerMapper.updateByPrimaryKeySelective(internshipLogger);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteInternshipLog(String id) {
        int row = internshipLoggerMapper.deleteByPrimaryKey(id);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean checkInternshipLog(InternshipLogger internshipLogger) {
        int row = internshipLoggerMapper.updateByPrimaryKeySelective(internshipLogger);
        if (row > 0) {
            return true;
        }
        return false;
    }
}
